<template>
<div>
    <input type="text" placeholder="请输入" v-model="keyword"> 
    <button @click="searchUsers">Search</button>
    <br>
    <hr>
</div>
  
</template>

<script>
import axios from 'axios'

export default {
    name:'Search',
    data() {
        return {
            keyword:''
        }
    },
    methods: {
        searchUsers(){
            // 请求成功前更新List数据
            this.$bus.$emit('data',{isFirst:false,isLoading:true,errMsg:'',users:[]})
            axios.get(`https://api.github.com/search/users?q=${this.keyword}`).then(
                response=>{
                    console.log('请求成功！');
                    // 请求成功后更新List数据
                    this.$bus.$emit('data',{isFirst:false,isLoading:true,errMsg:'',users:response.data.items})
                },
                error=>{
                    console.log('请求失败',error.message);
                    // 请求失败后更新List数据
                    this.$bus.$emit('data',{isFirst:false,isLoading:false,errMsg:error.message,users:[]})
                }
            )
        }
    }
}
</script>

<style>

</style>